class KhachhangController < ApplicationController
  attr_accessor :giohang
  @@giohang = Giohang.new
  @@giohang.userid = "";
  @@giohang.email = "";
  @@giohang.sdt = "";
  @@giohang.sp1 = "";
  @@giohang.sp2 = "";
  @@giohang.sp3 = "";
  @@giohang.sp4 = "";
  @@giohang.sp5 = "";
  def index
    @products = Product.all
    @giohangcuatoi = @@giohang
  end
  def gioithieu
    
  end
  def sanpham
    
  end
  def timkiem
  end

  def chitiet
    @product = Product.find(params[:id])
    @giohangcuatoi = @@giohang
  end

  def themvaogiohang
    @product = Product.find(params[:product_id])

    @result = "success"
    if(@product)
      if @@giohang.sp1 == ""
      @@giohang.sp1 = @product.id
      else
        if @@giohang.sp2 == ""
        @@giohang.sp2 = @product.id
        else
          if @@giohang.sp3 == ""
          @@giohang.sp3 = @product.id
          else
            if @@giohang.sp4 == ""
            @@giohang.sp4 = @product.id
            else
              if @@giohang.sp5 == ""
              @@giohang.sp5 = @product.id
              else
                @result = "error"
              end
            end
          end
        end
      end
    end
    redirect_to :back, :notice => @result == "success"?"da them vao gio hang":"gio hang da day"
  end

  def giohang
    @giohangcuatoi = @@giohang
    if(@@giohang.sp1 != "")
      @product1 = Product.find(@@giohang.sp1)
    end
    if(@@giohang.sp2 != "")
      @product2 = Product.find(@@giohang.sp2)
    end
    if(@@giohang.sp3 != "")
      @product3 = Product.find(@@giohang.sp3)
    end
    if(@@giohang.sp4 != "")
      @product4 = Product.find(@@giohang.sp4)
    end
    if(@@giohang.sp5 != "")
      @product5 = Product.find(@@giohang.sp5)
    end
  end

  def huygiohang
    @@giohang.userid = "";
    @@giohang.email = "";
    @@giohang.sdt = "";
    @@giohang.sp1 = "";
    @@giohang.sp2 = "";
    @@giohang.sp3 = "";
    @@giohang.sp4 = "";
    @@giohang.sp5 = "";
    redirect_to "khachhang_index_path"
  end

  def xacnhangiohang

  end

  def dathang

  end
end
